const service = require('../service/label.service');
const momentService = require('../service/moment.service');

class LabelController {
  async create(ctx, next) {
    const {product_list,date,address,remark} = ctx.request.body;
    const userId = ctx.user.id;
    const order_id = await service.create(userId,date,address,remark);
    for (let product of product_list) {
      const {product_id, count} = product;
      await service.addGood(order_id, product_id, count);
    }
    ctx.body = "订单创建成功";
  }

  async list(ctx, next) {
    const userId = ctx.user.id;
    const {limit, offset} = ctx.query;
    const result = await service.getLabels(userId,limit, offset);
    ctx.body = result;
  }

  async remove(ctx, next) {
    // 1.获取momentId
    const { orderId } = ctx.params;
    // 2.删除内容
    const result = await service.remove(orderId);
    ctx.body = `订单${orderId}删除成功`;
  }
}

module.exports = new LabelController();
